<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>CKEDITOR.ajax</title>
	<link rel="stylesheet" type="text/css" href="../test.css" />
	<script type="text/javascript" src="../../ckeditor.js"></script>
	<script type="text/javascript" src="../../_source/core/loader.js"></script>
	<script type="text/javascript" src="../test.js"></script>
	<script type="text/javascript">
	//<![CDATA[

CKEDITOR.loader.load( 'core/ajax' );

	//]]>
	</script>
	<script type="text/javascript">
	//<![CDATA[

CKEDITOR.test.addTestCase( (function()
{
	// Local reference to the "assert" object.
	var assert = CKEDITOR.test.assert;

	return {
		test_load_sync : function()
		{
			var data = CKEDITOR.ajax.load( '../_assets/sample.txt' );
			assert.areSame( 'Sample Text\r\n', data, 'The loaded data doesn\'t match' );
		},

		test_load_sync_404 : function()
		{
			var data = CKEDITOR.ajax.load( '../_assets/404.txt' );
			assert.isNull( data );
		},

		test_load_async : function()
		{
			var testCase = this;
			var callback = function( data )
			{
				testCase.resume( function()
					{
						assert.areSame( 'Sample Text\r\n', data, 'The loaded data doesn\'t match' );
					} );
			};

			CKEDITOR.ajax.load( '../_assets/sample.txt', callback );
			this.wait();
		},

		test_load_async_404 : function()
		{
			var testCase = this;
			var callback = function( data )
			{
				testCase.resume( function()
					{
						assert.isNull( data );
					} );
			};

			CKEDITOR.ajax.load( '../_assets/404.txt', callback );
			this.wait();
		},

		test_loadXml_sync : function()
		{
			var data = CKEDITOR.ajax.loadXml( '../_assets/sample.xml' );
			assert.isInstanceOf( CKEDITOR.xml, data );
			assert.isNotNull( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (null)' );
			assert.isNotUndefined( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (undefined)' );
		},

		test_loadXml_sync_404 : function()
		{
			var data = CKEDITOR.ajax.loadXml( '../_assets/404.xml' );
			assert.isNull( data );
		},

		test_loadXml_async : function()
		{
			var testCase = this;
			var callback = function( data )
			{
				testCase.resume( function()
					{
						assert.isInstanceOf( CKEDITOR.xml, data );
						assert.isNotNull( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (null)' );
						assert.isNotUndefined( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (undefined)' );
					} );
			};

			CKEDITOR.ajax.loadXml( '../_assets/sample.xml', callback );
			this.wait();
		},

		test_loadXml_async_404 : function()
		{
			var testCase = this;
			var callback = function( data )
			{
				testCase.resume( function()
					{
						assert.isNull( data );
					} );
			};

			CKEDITOR.ajax.loadXml( '../_assets/404.xml', callback );
			this.wait();
		},

		test_loadXml_sync_txt : function()
		{
			var data = CKEDITOR.ajax.loadXml( '../_assets/sample_xml.txt' );
			assert.isInstanceOf( CKEDITOR.xml, data );
			assert.isNotNull( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (null)' );
			assert.isNotUndefined( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (undefined)' );
		},

		test_loadXml_async_txt : function()
		{
			var testCase = this;
			var callback = function( data )
			{
				testCase.resume( function()
					{
						assert.isInstanceOf( CKEDITOR.xml, data );
						assert.isNotNull( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (null)' );
						assert.isNotUndefined( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (undefined)' );
					} );
			};

			CKEDITOR.ajax.loadXml( '../_assets/sample_xml.txt', callback );
			this.wait();
		},

		test_parseXml : function()
		{
			var data = new CKEDITOR.xml( '<?xml version="1.0" encoding="utf-8" ?><list><item id="test1" /><item id="test2" /></list>' );
			assert.isInstanceOf( CKEDITOR.xml, data );
			assert.isNotNull( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (null)' );
			assert.isNotUndefined( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (undefined)' );
		},

		test_parseXml_nbsp : function()
		{
			var data = new CKEDITOR.xml( '<?xml version="1.0" encoding="utf-8" ?><list><item id="test1">&nbsp;</item><item id="test2" /></list>' );
			assert.isInstanceOf( CKEDITOR.xml, data );
			assert.isNotNull( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (null)' );
			assert.isNotUndefined( data.selectSingleNode( '//list/item' ), 'The loaded data doesn\'t match (undefined)' );
		},

		name : document.title
	};
})() );

	//]]>
	</script>
</head>
<body>
</body>
</html>
